Dart Map operator ==
Syntax & Examples
Syntax of Map.operator ==
The syntax of Map.operator == operator is:
operator ==(Object other) → boolThis operator == operator of Map the equality operator.
Parameters
| Parameter | Optional/Required | Description |
|---|---|---|
other | required | the object to compare against |
✐ Examples
1 Check equality of two numbers
In this example,
- We declare two integers,
num1andnum2, with values 10 and 20 respectively. - We then use the equality operator
==to comparenum1andnum2. - Since
num1is not equal tonum2, the result isfalse. - We print the result to standard output.
Dart Program
void main() {
int num1 = 10;
int num2 = 20;
bool result = num1 == num2;
print('Are num1 and num2 equal? $result');
}Output
Are num1 and num2 equal? false
2 Check equality of two strings
In this example,
- We declare two strings,
str1andstr2, with values 'hello' and 'world' respectively. - We then use the equality operator
==to comparestr1andstr2. - Since
str1is not equal tostr2, the result isfalse. - We print the result to standard output.
Dart Program
void main() {
String str1 = 'hello';
String str2 = 'world';
bool result = str1 == str2;
print('Are str1 and str2 equal? $result');
}Output
Are str1 and str2 equal? false
3 Check equality of two lists
In this example,
- We declare two lists,
list1andlist2, containing integers 1, 2, and 3. - We then use the equality operator
==to comparelist1andlist2. - Since
list1is equal tolist2, the result istrue. - We print the result to standard output.
Dart Program
void main() {
List<int> list1 = [1, 2, 3];
List<int> list2 = [1, 2, 3];
bool result = list1 == list2;
print('Are list1 and list2 equal? $result');
}Output
Are list1 and list2 equal? true
Summary
In this Dart tutorial, we learned about operator == operator of Map: the syntax and few working examples with output and detailed explanation for each example.